package com.zhao.retry.demo.service.impl;

import com.zhao.retry.demo.service.DemoRetryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * Created on 2020/5/20.
 *
 * @author zhao
 * @email 136689260@qq.com
 */
@Slf4j
@Service
public class DemoRetryServiceImpl implements DemoRetryService {

    @Retryable(interceptor = "customMethodInterceptor", value = RuntimeException.class, maxAttempts = 4)
    @Override
    public String service(String param) {
        log.info("service {} ", param);
        throw new RuntimeException("");
    }

    @Recover
    public String recover(RuntimeException e, String param) {
        log.error("recover {} ", param, e);
        return "RuntimeException recover";
    }
}
